/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NoteView.java
 *
 * Created on May 17, 2011, 9:38:19 AM
 */
package views;

import controllers.NoteController;
import models.Note;

/**
 *
 * @author Steffen
 */
public class NoteView extends AbstractView {

    private NoteController noteCtr = null;
    
    public NoteView() {
        initComponents();
    }
    
    public NoteView(int noteId) {
        initComponents();
        noteCtr = new NoteController(noteId);
        this.setValues();
    }
    
    public NoteView(Note note) {
        initComponents();
        noteCtr = new NoteController(note);
        this.setValues();
    }
    
    // Metode til at sætte værdierne i brugerfladen
    public void setValues() {
        if(noteCtr != null) {
            
            // Henter noten fra controlleren
            Note note = noteCtr.getNote();
            
            if(note != null) {
                
                // Sætter værdierne i brugerfladen
                headline.setText(note.getTitle());
                text.setText(note.getText());
                
                this.createdDate.setText(note.getCreated());
                this.createdBy.setText(note.getCreatedPerson().getName());
                this.updatedDate.setText(note.getUpdated());
                this.updatedBy.setText(note.getUpdatedPerson().getName());
            }
        }
        
    }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        headline = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        text = new javax.swing.JTextPane();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        updatedDate = new javax.swing.JLabel();
        updatedBy = new javax.swing.JLabel();
        createdDate = new javax.swing.JLabel();
        createdBy = new javax.swing.JLabel();
        textEdited = new javax.swing.JLabel();
        textCreated = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        headline.setFont(new java.awt.Font("Lucida Grande", 0, 18));
        headline.setText("Overskrift");

        text.setBackground(javax.swing.UIManager.getDefaults().getColor("control"));
        text.setBorder(null);
        text.setEditable(false);
        text.setText("Halløj");
        text.setBounds(new java.awt.Rectangle(0, 0, 10, 10));
        jScrollPane1.setViewportView(text);

        jButton1.setText("Luk");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Ret notat");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        updatedDate.setText("00-00-0000");

        updatedBy.setText("Brian Mikkelsen");

        createdDate.setText("00-00-0000");

        createdBy.setText("Henning Stærk");

        textEdited.setFont(new java.awt.Font("Lucida Grande", 1, 13));
        textEdited.setText("Redigeret:");

        textCreated.setFont(new java.awt.Font("Lucida Grande", 1, 13));
        textCreated.setText("Oprettet:");

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 14));
        jLabel1.setText("|");

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 1, 14));
        jLabel2.setText("|");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(layout.createSequentialGroup()
                                .add(textEdited)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(updatedDate))
                            .add(layout.createSequentialGroup()
                                .add(textCreated)
                                .add(18, 18, 18)
                                .add(createdDate)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel2)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(updatedBy, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(jLabel1)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(createdBy, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton1))
                    .add(headline, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(headline)
                .add(14, 14, 14)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(textCreated)
                                .add(createdDate)
                                .add(jLabel1)
                                .add(createdBy))
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(textEdited))
                        .add(layout.createSequentialGroup()
                            .add(24, 24, 24)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(jLabel2)
                                .add(updatedBy)
                                .add(updatedDate))))
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jButton1)
                        .add(jButton2)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // Laver et nyt "EditNote" vindue, og sender ID'et med på noten
        new EditNoteView(noteCtr.getNote().getId()).setVisible(true);
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // Lukker vinduet her
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new NoteView().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel createdBy;
    private javax.swing.JLabel createdDate;
    private javax.swing.JLabel headline;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane text;
    private javax.swing.JLabel textCreated;
    private javax.swing.JLabel textEdited;
    private javax.swing.JLabel updatedBy;
    private javax.swing.JLabel updatedDate;
    // End of variables declaration//GEN-END:variables
}
